#!/bin/sh
#
# Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
#
# SPDX-License-Identifier: GPL-2.0-only
#

# Install the checkpatch pre-commit hook.

DIR="$( cd "$( dirname "$0" )" && pwd )"

PRECOMMIT_HOOK="../.git/hooks/pre-commit"
PRECOMMIT_SCRIPT="checkpatch-hook"
CHECKPATCH_CONF=".checkpatch.conf"

if [ -f $PRECOMMIT_HOOK ];
then
   echo "File $PRECOMMIT_HOOK already exists. Aborting."
   exit 1
else
    ln -s $DIR/$PRECOMMIT_SCRIPT $PRECOMMIT_HOOK
fi

if [ -f ../$CHECKPATCH_CONF ];
then
   echo "File ../$CHECKPATCH_CONF already exists. Aborting."
   exit 1
else
    ln -s $DIR/$CHECKPATCH_CONF ../$CHECKPATCH_CONF
fi

echo "Checkpatch pre-commit hook successfully installed!"
